package com.hubiao.pro.service.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * Description
 *
 * @author hubiao
 * @since 2021-01-30 0:24
 */
@Component
public class ReceiverListener implements MessageListener {

    private static Logger logger = LoggerFactory.getLogger( ReceiverListener.class );

    @Resource
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        RedisSerializer<String> valueSerializer = stringRedisTemplate.getStringSerializer();
        String deserialize = valueSerializer.deserialize( message.getBody() );
        logger.info( "收到的mq消息" + deserialize );
    }
}
